//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "DailyTenorJPYLibor.h"
using namespace Cephei::QL::Indexes::Ibor;
#include <gen/QL/Termstructures/YieldTermStructure.h>
#include <gen/QL/Currency.h>
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Indexes/IborIndex.h>
#include <gen/QL/Times/Period.h>
#include <gen/QL/Indexes/Ibor/DailyTenorLibor.h>
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL;
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::CDailyTenorJPYLibor (UInt32 settlementDays, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ h) : CDailyTenorLibor(CDailyTenorJPYLibor::typeid)
{
    CYieldTermStructure^ _Ch;
    try
    {
#ifdef HANDLE
        _phDailyTenorJPYLibor = NULL;
#endif
        QuantLib::Natural _settlementDays = (QuantLib::Natural)ValueHelper::Convert (settlementDays);
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>::IsSome::get (h))
        {
            _Ch = safe_cast<CYieldTermStructure^> (h->Value);
            _Ch->Lock();
        }
        Handle<QuantLib::YieldTermStructure>& _h = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>::IsSome::get (h) ? static_cast<Handle<QuantLib::YieldTermStructure>&> (_Ch->GetHandle ()) : Handle<QuantLib::YieldTermStructure>()); //1
        _ppDailyTenorJPYLibor = new boost::shared_ptr<QuantLib::DailyTenorJPYLibor> (new QuantLib::DailyTenorJPYLibor ( _settlementDays,  _h ));
        SetDailyTenorLibor (boost::dynamic_pointer_cast<QuantLib::DailyTenorLibor> (*_ppDailyTenorJPYLibor));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ch != nullptr) _Ch->Unlock();
    }
}
Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::CDailyTenorJPYLibor (boost::shared_ptr<QuantLib::DailyTenorJPYLibor>& childNative, Object^ owner) : CDailyTenorLibor(CDailyTenorJPYLibor::typeid)
{
#ifdef HANDLE
	_phDailyTenorJPYLibor = NULL;
#endif
	_ppDailyTenorJPYLibor = &childNative;
    _ppDailyTenorLibor = new boost::shared_ptr<QuantLib::DailyTenorLibor> (boost::dynamic_pointer_cast<QuantLib::DailyTenorLibor> (*_ppDailyTenorJPYLibor));
}
Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::CDailyTenorJPYLibor (QuantLib::DailyTenorJPYLibor& childNative, Object^ owner) : CDailyTenorLibor(CDailyTenorJPYLibor::typeid)
{
#ifdef HANDLE
	_phDailyTenorJPYLibor = NULL;
#endif
	_ppDailyTenorJPYLibor = new boost::shared_ptr<QuantLib::DailyTenorJPYLibor> (&childNative);
    _ppDailyTenorLibor = new boost::shared_ptr<QuantLib::DailyTenorLibor> (boost::dynamic_pointer_cast<QuantLib::DailyTenorLibor> (*_ppDailyTenorJPYLibor));
    _DailyTenorJPYLiborOwner = owner;
    _DailyTenorLiborOwner = owner;
}

Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::CDailyTenorJPYLibor (CDailyTenorJPYLibor^ copy) : CDailyTenorLibor(CDailyTenorJPYLibor::typeid)
{
#ifdef HANDLE
	_phDailyTenorJPYLibor = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppDailyTenorJPYLibor = new boost::shared_ptr<QuantLib::DailyTenorJPYLibor> (copy->GetShared());
        _ppDailyTenorLibor = new boost::shared_ptr<QuantLib::DailyTenorLibor> (boost::dynamic_pointer_cast<QuantLib::DailyTenorLibor> (*_ppDailyTenorJPYLibor));
    }
}
Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::CDailyTenorJPYLibor (System::Type^ t) : CDailyTenorLibor(CDailyTenorJPYLibor::typeid)
{
#ifdef HANDLE
	_phDailyTenorJPYLibor = NULL;
#endif
	if (!t->IsSubclassOf(CDailyTenorJPYLibor::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::CDailyTenorJPYLibor (QuantLib::Handle<QuantLib::DailyTenorJPYLibor>& childNative, Object^ owner)  : CDailyTenorLibor(CDailyTenorJPYLibor::typeid)
{
	_phDailyTenorJPYLibor = &childNative;
	_ppDailyTenorJPYLibor = &static_cast<boost::shared_ptr<QuantLib::DailyTenorJPYLibor>>(childNative.currentLink());
    _ppDailyTenorLibor = new boost::shared_ptr<QuantLib::DailyTenorLibor> (boost::dynamic_pointer_cast<QuantLib::DailyTenorLibor> (*_ppDailyTenorJPYLibor));
    _DailyTenorJPYLiborOwner = owner;
}
Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::CDailyTenorJPYLibor (QuantLib::Handle<QuantLib::DailyTenorJPYLibor> childNative)  : CDailyTenorLibor(CDailyTenorJPYLibor::typeid)
{
	_phDailyTenorJPYLibor = &childNative;
	_ppDailyTenorJPYLibor = &static_cast<boost::shared_ptr<QuantLib::DailyTenorJPYLibor>>(childNative.currentLink());
    _ppDailyTenorLibor = new boost::shared_ptr<QuantLib::DailyTenorLibor> (boost::dynamic_pointer_cast<QuantLib::DailyTenorLibor> (*_ppDailyTenorJPYLibor));
}
#endif
#ifdef STRUCT
Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::CDailyTenorJPYLibor (QuantLib::DailyTenorJPYLibor childNative)  : CDailyTenorLibor(CDailyTenorJPYLibor::typeid)
{
#ifdef HANDLE
	_phDailyTenorJPYLibor = NULL;
#endif
	_ppDailyTenorJPYLibor = new boost::shared_ptr<QuantLib::DailyTenorJPYLibor> (new QuantLib::DailyTenorJPYLibor (childNative));
    _ppDailyTenorLibor = new boost::shared_ptr<QuantLib::DailyTenorLibor> (boost::dynamic_pointer_cast<QuantLib::DailyTenorLibor> (*_ppDailyTenorJPYLibor));
}
#endif

Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::~CDailyTenorJPYLibor ()
{
    if (_ppDailyTenorJPYLibor != NULL)
    {
	    delete _ppDailyTenorJPYLibor;
        _ppDailyTenorJPYLibor = NULL;
    }
}
Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::!CDailyTenorJPYLibor ()
{
    if (_ppDailyTenorJPYLibor != NULL)
    {
	    delete _ppDailyTenorJPYLibor;
    }
}
QuantLib::DailyTenorJPYLibor& Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::GetReference ()
{
    if (_ppDailyTenorJPYLibor == NULL) throw gcnew NativeNullException ();
	return **_ppDailyTenorJPYLibor;
}
boost::shared_ptr<QuantLib::DailyTenorJPYLibor>& Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::GetShared ()
{
    if (_ppDailyTenorJPYLibor == NULL) throw gcnew NativeNullException ();
	return *_ppDailyTenorJPYLibor;
}
QuantLib::DailyTenorJPYLibor* Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::GetPointer ()
{
    if (_ppDailyTenorJPYLibor == NULL) throw gcnew NativeNullException ();
	return &**_ppDailyTenorJPYLibor;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::DailyTenorJPYLibor>& Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::GetHandle ()
{
	if (_phDailyTenorJPYLibor == NULL)
	{
		_phDailyTenorJPYLibor = new Handle<QuantLib::DailyTenorJPYLibor> (*_ppDailyTenorJPYLibor);
	}
	return *_phDailyTenorJPYLibor;
}
#endif
bool Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor::HasNative () 
{
	return (_ppDailyTenorJPYLibor != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Indexes::Ibor::IDailyTenorJPYLibor^ Cephei::QL::Indexes::Ibor::CDailyTenorJPYLibor_Factory::Create (UInt32 settlementDays, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ h)
{
    return gcnew CDailyTenorJPYLibor ( settlementDays,  h);
}
